import {ResponseResult} from "~~/server/resources/types/response-result";
import {NotificationType} from "~/resource/enums/notification-type";

const useNotificationType = (code: string): NotificationType => {
    switch (code) {
        case "000000": {
            return NotificationType.SUCCESS;
        }
        case "C00001": {
            return NotificationType.ERROR;
        }
        default: {
            return NotificationType.WARNING;
        }
    }
}

export const useResponseNotification = (responseResult: ResponseResult<any>) => {
    return {
        type: useNotificationType(responseResult.code),
        text: responseResult.message
    };
}

export const useInfoNotification = (text: string) => {
    return {
        type: NotificationType.INFO,
        text: text
    };
}

export const useWarningNotification = (text: string) => {
    return {
        type: NotificationType.WARNING,
        text: text
    };
}
export const useErrorNotification = (text: string) => {
    return {
        type: NotificationType.ERROR,
        text: text
    };
}
export const useSuccessNotification = (text: string) => {
    return {
        type: NotificationType.SUCCESS,
        text: text
    };
}